<?php
class Reports extends CI_Controller 
{
	function __construct()
	{
		parent::__construct();
		if(!check_auth()) { redirect("/login/auth"); }
		$this->load->model('reports_model');
		$this->load->helper('template');
		$this->load->helper('functions');
	}
	
	function index()
	{
		
	
	}
	
	function coordination()
	{
		$data['date_start_set'] = "01-".date("m-Y");
		$data['date_end_set'] = date("d-m-Y");
	
		$data['table1'] = "";
		$data['table2'] = "";
		$data['table3'] = "";
		
		if (count($_POST) == 0) {
			//Original page load
			
		} else {
			//Posted back, and now I can use the $post variable like this
			
			$this->form_validation->set_rules('date_start', 'Date Start', 'required');
			$this->form_validation->set_rules('date_end', 'Date End', 'required');
		
			if ($this->form_validation->run() != FALSE)
			{
				$date_start = $this->input->post('date_start'); 
				$date_end = $this->input->post('date_end');
				
				$data['date_start_set'] = $date_start;
				$data['date_end_set'] = $date_end;
				
				$data['table1'] = $this->reports_model->getReportsCoordination($date_start, $date_end, 1);
				$data['table2'] = $this->reports_model->getReportsCoordination($date_start, $date_end, 2);
				$data['table3'] = $this->reports_model->getReportsCoordination($date_start, $date_end, 3);
			}
			else
			{
				setMessage("danger", validation_errors());
			}
		} 
	
		loadViewReports('reports_coordination', $data);
	}
	
	
	function mailing_room()
	{
		$data['date_start_set'] = "01-".date("m-Y");
		$data['date_end_set'] = date("d-m-Y");

		$data['table1'] = "";
		$data['table2'] = "";
		$data['table3'] = "";
		
		if (count($_POST) == 0) {
			//Original page load
			
		} else {
			//Posted back, and now I can use the $post variable like this
			
			$this->form_validation->set_rules('date_start', 'Date Start', 'required');
			$this->form_validation->set_rules('date_end', 'Date End', 'required');
		
			if ($this->form_validation->run() != FALSE)
			{
				$date_start = $this->input->post('date_start'); 
				$date_end = $this->input->post('date_end');
				
				$data['date_start_set'] = $date_start;
				$data['date_end_set'] = $date_end;
				
				$data['table1'] = $this->reports_model->getReportsMailingRoom($date_start, $date_end, 1);
				$data['table2'] = $this->reports_model->getReportsMailingRoom($date_start, $date_end, 2);
				$data['table3'] = $this->reports_model->getReportsMailingRoom($date_start, $date_end, 3);
				$data['date_start_end'] = $date_start."&nbsp;&nbsp;s/d&nbsp;&nbsp;".$date_end;
			}
			else
			{
				setMessage("danger", validation_errors());
			}
		} 
	
		loadViewReports('reports_mailing_room', $data);
	}
	
	function overtime($parameter = null)
	{
		$data['date_start_set'] = "01-".date("m-Y");
		$data['date_end_set'] = date("d-m-Y");
	
		$data['table1'] = "";
		$data['table2'] = "";
		$data['table3'] = "";
		
		if (count($_POST) == 0) {
			//Original page load
			
			//echo $parameter;
			//die();
			
			if(isset($parameter)) // untuk print report per dokumen
			{
				$parameter = urldecode(urldecode($parameter));
				$data['rdetail'] = $this->reports_model->getReportsOvertimeDetail($parameter);
				$data['rdetailperson'] = $this->reports_model->getReportsOvertimeDetailPerson($parameter);
				
				$this->load->view('reports_overtime_detail', $data);
				
			}
			else
			{
				loadViewReports('reports_overtime', $data);
			}
			
		} 
		else 
		{
			//Posted back, and now I can use the $post variable like this
			
			$this->form_validation->set_rules('date_start', 'Date Start', 'required');
			$this->form_validation->set_rules('date_end', 'Date End', 'required');
		
			if ($this->form_validation->run() != FALSE)
			{
				$date_start = $this->input->post('date_start'); 
				$date_end = $this->input->post('date_end');
				
				$data['date_start_set'] = $date_start;
				$data['date_end_set'] = $date_end;
				
				$data['table1'] = $this->reports_model->getReportsOvertime($date_start, $date_end, 1);
				$data['table2'] = $this->reports_model->getReportsOvertime($date_start, $date_end, 2);
				$data['table3'] = $this->reports_model->getReportsOvertime($date_start, $date_end, 3);
				$data['date_start_end'] = $date_start."&nbsp;&nbsp;s/d&nbsp;&nbsp;".$date_end;
			}
			else
			{
				setMessage("danger", validation_errors());
			}
			
			loadViewReports('reports_overtime', $data);
		} 
		
	}
	
	function paging_info()
	{
		$data['date_start_set'] = "01-".date("m-Y");
		$data['date_end_set'] = date("d-m-Y");
	
		$data['table1'] = "";
		$data['table2'] = "";
		$data['table3'] = "";
		
		if (count($_POST) == 0) {
			//Original page load
			
			//echo $parameter;
			//die();
			
			// if(isset($parameter)) // untuk print report per dokumen
			// {
				// $parameter = urldecode(urldecode($parameter));
				// //$data['rdetail'] = $this->reports_model->getReportsOvertimeDetail($parameter);
				// //$data['rdetailperson'] = $this->reports_model->getReportsOvertimeDetailPerson($parameter);
				
				// $this->load->view('reports_overtime_detail', $data);
				
			// }
			// else
			// {
				// loadViewReports('reports_overtime', $data);
			// }
			
			loadViewReports('reports_paging_info', $data);
		} 
		else 
		{
			//echo "qwe";die();
			//Posted back, and now I can use the $post variable like this
			
			$this->form_validation->set_rules('date_start', 'Date Start', 'required');
			$this->form_validation->set_rules('date_end', 'Date End', 'required');
		
			if ($this->form_validation->run() != FALSE)
			{
				$date_start = $this->input->post('date_start'); 
				$date_end = $this->input->post('date_end');
				
				$data['date_start_set'] = $date_start;
				$data['date_end_set'] = $date_end;
				
				$data['table2'] = $this->reports_model->getReportsPagingInfo($date_start, $date_end);
				$data['date_start_end'] = $date_start."&nbsp;&nbsp;s/d&nbsp;&nbsp;".$date_end;
			}
			else
			{
				setMessage("danger", validation_errors());
			}
			
			loadViewReports('reports_paging_info', $data);
		} 
		
	}
	
	function parkir($parameter = null)
	{
		$data['date_start_set'] = "01-".date("m-Y");
		$data['date_end_set'] = date("d-m-Y");
		
		$data['htable1'] = "";
		$data['htable2'] = "";
		$data['htable3'] = "";
		$data['table1'] = "";
		$data['table2'] = "";
		$data['table3'] = "";
		
		if (count($_POST) == 0) {
			//Original page load
			
			//echo $parameter;
			//die();
			
			if(isset($parameter)) // untuk print report per dokumen
			{
				$parameter = urldecode(urldecode($parameter));
				// $data['rdetail'] = $this->reports_model->getReportsOvertimeDetail($parameter);
				// $data['rdetailperson'] = $this->reports_model->getReportsOvertimeDetailPerson($parameter);
				
				// $this->load->view('reports_overtime_detail', $data);
				
			}
			else
			{
				loadViewReports('reports_parking', $data);
			}
			
		} 
		else 
		{
			//Posted back, and now I can use the $post variable like this
			
			$this->form_validation->set_rules('date_start', 'Date Start', 'required');
			$this->form_validation->set_rules('date_end', 'Date End', 'required');
		
			if ($this->form_validation->run() != FALSE)
			{
				$date_start = $this->input->post('date_start'); 
				$date_end = $this->input->post('date_end');
				
				$data['date_start_set'] = $date_start;
				$data['date_end_set'] = $date_end;
				
				$data['htable1'] = $this->reports_model->getReportsParkingPriceHeader(1); // motor
				$data['htable2'] = $this->reports_model->getReportsParkingPriceHeader(2); // mobil reserved
				$data['htable3'] = $this->reports_model->getReportsParkingPriceHeader(3); // mobil non-reserved
				
				$data['table1'] = $this->reports_model->getReportsParking($date_start, $date_end, 1, $data['htable1']['DET_QTY_AWAL'], $data['htable1']['DET_QTY_AKHIR']);
				$data['table2'] = $this->reports_model->getReportsParking($date_start, $date_end, 2, $data['htable2']['DET_QTY_AWAL'], $data['htable2']['DET_QTY_AKHIR']);
				$data['table3'] = $this->reports_model->getReportsParking($date_start, $date_end, 3, $data['htable3']['DET_QTY_AWAL'], $data['htable3']['DET_QTY_AKHIR']);
				
				$data['date_start_end'] = $date_start."&nbsp;&nbsp;s/d&nbsp;&nbsp;".$date_end;
			}
			else
			{
				setMessage("danger", validation_errors());
			}
			
			loadViewReports('reports_parking', $data);
		} 
		
	}
    
    //=========================ADD BY ANDI SISWANTO================================================
    function public_room()  //10-07-2014
	{
		$data['date_start_set'] = "01-".date("m-Y");
		$data['date_end_set'] = date("d-m-Y");
	
		$data['table1'] = "";
		$data['table2'] = "";
		$data['table3'] = "";
		
        
		if (count($_POST) == 0) {
			//Original page load
			
		} else {
			//Posted back, and now I can use the $post variable like this
			
			$this->form_validation->set_rules('date_start', 'Date Start', 'required');
			$this->form_validation->set_rules('date_end', 'Date End', 'required');
		
			if ($this->form_validation->run() != FALSE)
			{
				$date_start = $this->input->post('date_start'); 
				$date_end = $this->input->post('date_end');
				
				$data['date_start_set'] = $date_start;
				$data['date_end_set'] = $date_end;
				
				//$data['table1'] = $this->reports_model->getReportsCoordination($date_start, $date_end, 1);
				$data['table2'] = $this->reports_model->getReportsPublicRoom($date_start, $date_end, 2);
				//$data['table3'] = $this->reports_model->getReportsCoordination($date_start, $date_end, 3);
			}
			else
			{
				setMessage("danger", validation_errors());
			}
		} 
	
		loadViewReports('reports_publicroom', $data);
	}
    
    function repair_maintenance() //8-07-2014
	{
		$data['date_start_set'] = "01-".date("m-Y");
		$data['date_end_set'] = date("d-m-Y");
	
		$data['table1'] = "";
		$data['table2'] = "";
		$data['table3'] = "";
		
        
		if (count($_POST) == 0) {
			//Original page load
            //langsung turun ke LoadViewReports
			
		} else {
			//Posted back, and now I can use the $post variable like this
			
			$this->form_validation->set_rules('date_start', 'Date Start', 'required');
			$this->form_validation->set_rules('date_end', 'Date End', 'required');
		
			if ($this->form_validation->run() != FALSE)
			{
				$date_start = $this->input->post('date_start'); 
				$date_end = $this->input->post('date_end');
				
				$data['date_start_set'] = $date_start;
				$data['date_end_set'] = $date_end;
				
				//$data['table1'] = $this->reports_model->getReportsCoordination($date_start, $date_end, 1);
				$data['table2'] = $this->reports_model->getReportsRepairMaintenance($date_start, $date_end, 2);
				//$data['table3'] = $this->reports_model->getReportsCoordination($date_start, $date_end, 3);
			}
			else
			{
				setMessage("danger", validation_errors());
			}
		} 
	
		loadViewReports('reports_repairmaintenance', $data);
	}
    function sik() //10-07-2014
	{
		$data['date_start_set'] = "01-".date("m-Y");
		$data['date_end_set'] = date("d-m-Y");
	
		$data['table1'] = "";
		$data['table2'] = "";
		$data['table3'] = "";
		
        
		if (count($_POST) == 0) {
			//Original page load
            //langsung turun ke LoadViewReports
			
		} else {
			//Posted back, and now I can use the $post variable like this
			
			$this->form_validation->set_rules('date_start', 'Date Start', 'required');
			$this->form_validation->set_rules('date_end', 'Date End', 'required');
		
			if ($this->form_validation->run() != FALSE)
			{
				$date_start = $this->input->post('date_start'); 
				$date_end = $this->input->post('date_end');
				
				$data['date_start_set'] = $date_start;
				$data['date_end_set'] = $date_end;
				
				//$data['table1'] = $this->reports_model->getReportsCoordination($date_start, $date_end, 1);
				$data['table2'] = $this->reports_model->getReportsSik($date_start, $date_end, 2);
				//$data['table3'] = $this->reports_model->getReportsCoordination($date_start, $date_end, 3);
			}
			else
			{
				setMessage("danger", validation_errors());
			}
		} 
	
		loadViewReports('reports_sik', $data);
	}
    function saran() //11-07-2014
	{
		$data['date_start_set'] = "01-".date("m-Y");
		$data['date_end_set'] = date("d-m-Y");
	
		$data['table1'] = "";
		$data['table2'] = "";
		$data['table3'] = "";
		
        
		if (count($_POST) == 0) {
			//Original page load
            //langsung turun ke LoadViewReports
			
		} else {
			//Posted back, and now I can use the $post variable like this
			
			$this->form_validation->set_rules('date_start', 'Date Start', 'required');
			$this->form_validation->set_rules('date_end', 'Date End', 'required');
		
			if ($this->form_validation->run() != FALSE)
			{
				$date_start = $this->input->post('date_start'); 
				$date_end = $this->input->post('date_end');
				
				$data['date_start_set'] = $date_start;
				$data['date_end_set'] = $date_end;
				
				//$data['table1'] = $this->reports_model->getReportsCoordination($date_start, $date_end, 1);
				$data['table2'] = $this->reports_model->getReportsSaran($date_start, $date_end, 2);
				//$data['table3'] = $this->reports_model->getReportsCoordination($date_start, $date_end, 3);
			}
			else
			{
				setMessage("danger", validation_errors());
			}
		} 
	
		loadViewReports('reports_saran', $data);
	}
    function outstanding_ga() //11-07-2014
	{
		$data['date_start_set'] = "01-".date("m-Y");
		$data['date_end_set'] = date("d-m-Y");
	
		$data['table1'] = "";
		$data['table2'] = "";
		$data['table3'] = "";
		
        
		if (count($_POST) == 0) {
			//Original page load
            //langsung turun ke LoadViewReports
			
		} else {
			//Posted back, and now I can use the $post variable like this
			
			$this->form_validation->set_rules('date_start', 'Date Start', 'required');
			$this->form_validation->set_rules('date_end', 'Date End', 'required');
		
			if ($this->form_validation->run() != FALSE)
			{
				$date_start = $this->input->post('date_start'); 
				$date_end = $this->input->post('date_end');
				
				$data['date_start_set'] = $date_start;
				$data['date_end_set'] = $date_end;
				
				//$data['table1'] = $this->reports_model->getReportsCoordination($date_start, $date_end, 1);
				$data['table2'] = $this->reports_model->getReportsOutstandingGa($date_start, $date_end, 2);
				//$data['table3'] = $this->reports_model->getReportsCoordination($date_start, $date_end, 3);
			}
			else
			{
				setMessage("danger", validation_errors());
			}
		} 
	
		loadViewReports('reports_outstandingga', $data);
	}
    function space_management() //11-07-2014
	{
		$data['date_start_set'] = "01-".date("m-Y");
		$data['date_end_set'] = date("d-m-Y");
	
		$data['table1'] = "";
		$data['table2'] = "";
		$data['table3'] = "";
		
        
		if (count($_POST) == 0) {
			//Original page load
            //langsung turun ke LoadViewReports
			
		} else {
			//Posted back, and now I can use the $post variable like this
			
			$this->form_validation->set_rules('date_start', 'Date Start', 'required');
			$this->form_validation->set_rules('date_end', 'Date End', 'required');
		
			if ($this->form_validation->run() != FALSE)
			{
				$date_start = $this->input->post('date_start'); 
				$date_end = $this->input->post('date_end');
				
				$data['date_start_set'] = $date_start;
				$data['date_end_set'] = $date_end;
				
				//$data['table1'] = $this->reports_model->getReportsCoordination($date_start, $date_end, 1);
				$data['table2'] = $this->reports_model->getReportsSpaceManagement($date_start, $date_end, 2);
				//$data['table3'] = $this->reports_model->getReportsCoordination($date_start, $date_end, 3);
			}
			else
			{
				setMessage("danger", validation_errors());
			}
		} 
	
		loadViewReports('reports_spacemanagement', $data);
	}
    
    function traffic() //15-07-2014
	{
		$data['date_start_set'] = "01-".date("m-Y");
		$data['date_end_set'] = date("d-m-Y");
	
		$data['table1'] = "";
		$data['table2'] = "";
		$data['table3'] = "";
		
        
		if (count($_POST) == 0) {
			//Original page load
            //langsung turun ke LoadViewReports
			
		} else {
			//Posted back, and now I can use the $post variable like this
			
			$this->form_validation->set_rules('date_start', 'Date Start', 'required');
			$this->form_validation->set_rules('date_end', 'Date End', 'required');
		
			if ($this->form_validation->run() != FALSE)
			{
				$date_start = $this->input->post('date_start'); 
				$date_end = $this->input->post('date_end');
                $lantai = $this->input->post('lantai'); 
				$serial = $this->input->post('serial');
				
				$data['date_start_set'] = $date_start;
				$data['date_end_set'] = $date_end;
				$data['lantai_set'] = $lantai;
				$data['serial_set'] = $serial;
                
				//$data['table1'] = $this->reports_model->getReportsCoordination($date_start, $date_end, 1);
				$data['table2'] = $this->reports_model->getReportsTraffic($date_start, $date_end, $lantai, $serial, 2);
				//$data['table3'] = $this->reports_model->getReportsCoordination($date_start, $date_end, 3);
			}
			else
			{
				setMessage("danger", validation_errors());
			}
		} 
	
		loadViewReports('reports_traffic', $data);
	}
    //==============================================END ANDI SISWANTO===========================================
}
?>